from multiprocessing import Pool


# Task函数
def helper(i):
    print(f"helper: {i}")
    return i * i


if __name__ == '__main__':

    # 创建进程池
    process_pool = Pool(processes=3)

    # Pool.apply()
    process_pool.apply(helper, args=(1, ))
    process_pool.apply_async(helper, args=(1,))

    # Pool.map()
    process_pool.map(helper, range(5))
    process_pool.map_async(helper, range(5))

    # Process.get()
    result = []
    for i in range(5):
        process = process_pool.apply_async(helper, args=(1,))
        result.append(process)

    process_pool.close()
    process_pool.join()

    for process in result:
        print(process.get())
